class Solution {
    vector<vector<int>> result;
    vector<int> tmp;
    vector<int> arr = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };

    void backTracking(int k, int n, int sum, int startIndex)
    {
        if (sum > n) return;
        if (k == 0)
        {
            if (sum == n)
            {
                result.push_back(tmp);
            }
            return;
        }
        for (int i = startIndex; i < 9 && k > 0; ++i)
        {
            tmp.push_back(arr[i]);
            sum += arr[i];
            backTracking(k - 1, n, sum, i + 1);
            tmp.pop_back();
            sum -= arr[i];
        }
    }
public:
    vector<vector<int>> combinationSum3(int k, int n) {
        backTracking(k, n, 0, 0);
        return result;
    }
};